package com.lhr.common.util;

import java.io.File;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

import com.lhr.common.util.domain.EmailInfo;

public class EmailUtil {
	public static void sendHtmlEmail(EmailInfo emailInfo,String toEmail,String toName,String subject,String htmlMsg) throws EmailException{
		sendHtmlEmail(emailInfo, toEmail, toName, subject, htmlMsg,null);
	}
	
	public static void sendHtmlEmail(EmailInfo emailInfo,String toEmail,String toName,String subject,String htmlMsg,File accessories) throws EmailException{
		HtmlEmail email = new HtmlEmail();
		email.setHostName(emailInfo.getHostName());
		email.setSmtpPort(emailInfo.getPort());
		email.setSSL(emailInfo.isSSL());
		email.addTo(toEmail,toName);
		email.setFrom(emailInfo.getFromEmail(), emailInfo.getFromName());  
		email.setAuthentication(emailInfo.getAuthenticationEmail(),emailInfo.getAuthenticationPwd());
		email.setCharset(emailInfo.getCharset());
		if(accessories != null)
			email.embed(accessories);
		email.setSubject(subject);
		email.setHtmlMsg(htmlMsg);
		email.send();
	}
	
}
